#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
调试Web API的脚本
"""

import requests
import json
import traceback

def test_web_api():
    """测试Web API"""
    print("=== 调试Web API ===\n")
    
    url = "http://127.0.0.1:5000/api/cluster/test_data_api.csv"
    
    # 测试数据
    test_data = {
        'algorithm': 'spectral',
        'n_clusters': 3
    }
    
    print(f"请求URL: {url}")
    print(f"请求数据: {json.dumps(test_data, indent=2)}")
    print("\n发送请求...")
    
    try:
        response = requests.post(url, json=test_data, timeout=30)
        
        print(f"\n响应状态码: {response.status_code}")
        print(f"响应头: {dict(response.headers)}")
        
        try:
            response_json = response.json()
            print(f"\n响应JSON:")
            print(json.dumps(response_json, indent=2, ensure_ascii=False))
        except:
            print(f"\n响应文本: {response.text}")
            
    except Exception as e:
        print(f"\n请求失败: {e}")
        print(f"错误详情: {traceback.format_exc()}")

if __name__ == "__main__":
    test_web_api()